Skip to content

Retry a throttled DeleteSecret in the Secrets Manager integration tests - #162

Draft
AlexDaines wants to merge 1 commit into
developfrom
secrets-manager-delete-throttle
Draft

AlexDaines wants to merge 1 commit into
developfrom
secrets-manager-delete-throttle

Conversation

@AlexDaines

Copy link
Copy Markdown
Collaborator

Description

Secrets Manager sometimes throttles a DeleteSecret that comes soon after a write to the secret. CloudTrail records the answer as ThrottlingException, "Request throttled due to resource contention", and the client sees HTTP 400. The released client treats only HTTP 429 as a throttle, so it does not retry this answer. It raises a plain CallError with no error code:

smithy_core.exceptions.CallError: Unknown error for operation com.amazonaws.secretsmanager#DeleteSecret - status: 400 - reason: Bad Request

Since these tests entered develop on 19 November, 9 of 122 pull request builds failed on this error, 2 of them also in the teardown of the secret_name fixture. smithy-lang/smithy-python#955 makes the client retry it, but it is in no release yet.

Fix

delete_secret_with_retry runs the delete through wait_until, like the S3 helper until_visible: an unmodeled HTTP 400 becomes a sentinel, and wait_until retries it each second for up to 5 seconds. All three DeleteSecret calls of these tests use it.

The error carries no error code, so another unmodeled HTTP 400 (an access-denied answer, for example) is retried too. If it clears within 5 seconds, the test passes. If it stays, the test fails 5 seconds late, with the CallError in the cause chain. Modeled errors are not retried. response_metadata is always set on a CallError, so the status check is safe.

The helper has a TODO to remove it when the smithy pins in pyproject.toml move to a release with #955.

Testing

Ran these tests against a fake Secrets Manager with the released packages, in async and sync modes. A throttle on the first one or two attempts passes after the retries. A throttle on each attempt fails after 5 seconds with TimeoutError, and the log shows the CallError. ResourceNotFoundException fails at once. Without this change, the fake fails the same tests with the error above. ruff and pyright pass.

I did not run the tests against the live service. The pull request build does that, but the error shows in about 1 build in 14, so one green build does not prove the retry. The 5 seconds are a first value: no build shows how long the throttle lasts, because the client made one attempt each time.

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

Secrets Manager sometimes answers DeleteSecret with HTTP 400
ThrottlingException. The released client does not retry it and raises a
plain CallError, which failed 9 of 122 pull request builds since
19 November.

delete_secret_with_retry retries an unmodeled HTTP 400 on the delete
each second for up to 5 seconds. All three DeleteSecret calls of these
tests use it. Remove it when the pins move to a smithy-python release
with smithy-lang/smithy-python#955.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant